﻿<%@ Page Title="ForestStandard" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="jnagr.Web.ForestStandard.List" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <style>
        html, body {
            height: 100%;
        }
    </style>
    <script type="text/javascript">
        var areaName;
        var pet;
        var sstage = [{ "id": "无", "text": "无", "selected": true }, { "id": "卵", "text": "卵" }, { "id": "幼虫", "text": "幼虫" }, { "id": "蛹", "text": "蛹" }, { "id": "成虫", "text": "成虫" }];
        var sstatisticunits = [{ "id": "有卵株率", "text": "有卵株率", "selected": true }, { "id": "有蛹株率", "text": "有蛹株率" }, { "id": "条/百叶", "text": "条/百叶" }, { "id": "有虫株率(%)", "text": "有虫株率(%)" }, { "id": "枝梢被害率", "text": "枝梢被害率" }, { "id": "条/50cm标准枝", "text": "条/50cm标准枝" }, { "id": "粒/株", "text": "粒/株" }, { "id": "头/株", "text": "头/株" }, { "id": "头(只)/株", "text": "头(只)/株" }, { "id": "条/株", "text": "条/株" }];

        $.extend($.fn.tree.methods, {
            getLevel: function (jq, target) {
                var l = $(target).parentsUntil("ul.tree", "ul");
                return l.length + 1;
            }
        });
        $(function () {
            InitTree();
            InitGird();
            InitSearch();
        });
        function InitTree() {
            $('#pt').tree({
                width: '100%', //宽度                
                lines: true,
                //data: provincetree,   
                url: '../areainfo/GetArea.ashx', //请求数据的页面 
                method: 'post',
                queryParams: { "action": "querymyco" },
                onBeforeExpand: function (node) {
                    //$("#pt").tree("options").queryParams = { "action": "queryyb" };
                    //$('#pt').tree('options').url = "../areainfo/GetArea.ashx?pid=" + node.id;
                },
                onClick: function (node) {
                    if (node.text != "") {
                        var lv = $('#pt').tree("getLevel", node.target);
                        var spro = "";
                        var scity = "";
                        var scou = "";
                        if (lv == 1) {
                            spro = '全国';
                        }
                        if (lv == 2) {
                            spro = node.text;
                        }
                        if (lv == 3) {
                            scity = node.text;
                            spro = $('#pt').tree("getParent", node.target).text;
                        }
                        if (lv == 4) {
                            scou = node.text;
                            var node1 = $('#pt').tree("getParent", node.target)
                            scity = node1.text;
                            spro = $('#pt').tree("getParent", node1.target).text;
                        }
                        areaName = spro + scity + scou;
                        $('#aname').val(areaName);
                        var encode = encodeURI(encodeURI(areaName));
                        $('#sname').combobox({
                            url: "../areastanderdinfo/GetAreaStanderd.ashx?action=ddllist&aname='" + encode + "'",
                            valueField: 'asid',
                            textField: 'sname',
                            panelHeight: 'auto',
                            width:120,
                            editable: false,
                            onLoadSuccess: function () {
                                var data = $('#sname').combobox('getData');
                                if (data.length > 0)
                                    $("#sname").combobox('select', data[0].caid);
                            }
                        });
                    }
                },
                onLoadSuccess: function (node, param) {
                    $('#pt').tree("collapseAll");
                }
            });
        }
        //增加查询参数，重新加载表格  
        function reloadgrid() {

            //查询参数直接添加在queryParams中      
            var queryParams = $('#tt').datagrid('options').queryParams;
            $('#tt').datagrid('options').queryParams = queryParams;
            $("#tt").datagrid('reload');

        }

        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '预警级别规则列表', //表格标题
                url: 'Getstandard.ashx', //请求数据的页面
                sortName: 'aname', //排序字段
                idField: 'Id', //标识字段,主键
                iconCls: '', //标题左边的图标
                //width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: true,
                method: 'post',
                columns: [[
                    { field: 'ckb', checkbox: true },
	                { title: '地区名', field: 'aname', width: 150, sortable: true },
                    { title: '类别', field: 'sname', width: 100 },
                    { title: '有害生物', field: 'ForestPets', width: 100 },
                    { title: '阶段', field: 'Stage', width: 80 },
                    { title: '统计单位', field: 'statisticunits', width: 150 },
                    { title: '最低值', field: 'harmdegreelow', width: 80 },
                    { title: '中间值', field: 'harmdegreecenter', width: 80 },
                    { title: '最高值', field: 'harmdegreeup', width: 80 }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });


        }
        function InitSearch() {
            $("#ipt_search").searchbox({
                width: 200,
                //iconCls: 'icon-save',
                searcher: function (val, name) {
                    $('#tt').datagrid('options').queryParams.search_type = name;
                    $('#tt').datagrid('options').queryParams.search_value = val;
                    $('#tt').datagrid('reload');
                },
                prompt: '请输入查询信息'
            });
            $('#pets').tree({
                url: '../harmfulinfo/GetHarm.ashx', //请求数据的页面               
                lines: true,
                method: 'post',
                queryParams: { "action": "query" },
                formatter: function (node) {
                    return node.bm + " " + node.text + " " + node.ldxm + " " + node.rvalue;
                },
                onClick: function (node) {
                    if (node.text != "") {
                        pet = node.text;
                        $('#ForestPets').val(pet);
                    }
                },
                onLoadSuccess: function (node, param) {
                    $('#pets').tree("collapseAll");
                }
            });
            $("#Stage").combobox({
                required: true,
                panelHeight: 'auto',
                width: 80,
                data: sstage,
                editable: false,
                valueField: 'id',
                textField: 'text'
            });
            $("#statisticunits").combobox({
                required: true,
                panelHeight: 'auto',
                width: 120,
                data: sstatisticunits,
                editable: false,
                valueField: 'id',
                textField: 'text'
            });
        }
        function newUser() {
            $('#fm').form('clear');
            $('#dlg').dialog('open').dialog('setTitle', '添加类别');
            $('#aname').val(areaName);
            $('#ForestPets').val(pet);
            var encode = encodeURI(encodeURI(areaName));
            $('#sname').combobox({
                url: "../areastanderdinfo/GetAreaStanderd.ashx?action=ddllist&aname='" +encode+"'",
                valueField: 'asid',
                textField: 'sname',
                panelHeight: 'auto',
                editable: false,
                onLoadSuccess: function () {
                    var data = $('#sname').combobox('getData');
                    if (data.length > 0)
                        $("#sname").combobox('select', data[0].asid);
                }
            });
            document.getElementById("test").value = "add";
        }
        //修改管理员  
        function editUser() {
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要修改的行！", "info");
            }
            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '修改类别');
                document.getElementById("test").value = "modify";
                $('#fm').form('load', row);
                var encode = encodeURI(encodeURI(row.aname));
                $('#sname').combobox({
                    url: "../areastanderdinfo/GetAreaStanderd.ashx?action=ddllist&aname='" + encode + "'",
                    valueField: 'asid',
                    textField: 'sname',
                    panelHeight: 'auto',
                    editable: false,
                    onLoadSuccess: function () {
                        var data = $('#sname').combobox('getData');
                        if (data.length > 0)
                            $("#sname").combobox('select', row.asid);
                    }
                });
                document.getE
            }
        }
        //添加        
        function saveUser() {
            var test = document.getElementById("test").value;
            var f = $('#fm');
            if (test == "add") {
                f.form('submit', {
                    url: "Getstandard.ashx?action=" + test,
                    onSubmit: function () {
                        var p = $('#ForestPets').val();
                        if (p == "")
                        {
                            $.messager.alert("提示", "有害生物不能为空！", "info");
                            return false;
                        }
                        return $(this).form('validate');                        
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $.messager.alert("提示", "恭喜您，信息添加成功", "info");
                            $('#tt').datagrid('reload');
                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });

            } else {

                $('#fm').form('submit', {
                    url: "Getstandard.ashx?action=" + test,
                    onSubmit: function () {
                        var p = $('#ForestPets').val();
                        if (p == "") {
                            $.messager.alert("提示", "有害生物不能为空！", "info");
                            return false;
                        }
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $('#tt').datagrid('clearSelections');
                            $.messager.alert("提示", "恭喜您，信息修改成功", "info");
                            $('#tt').datagrid('reload');

                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });
            }
        }
        function removeUser() {
            var test = document.getElementById("test").value = "delete";
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (row) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'Getstandard.ashx?asid=' + row.Id + "&action=" + test,
                            onSubmit: function () {
                                //return $(this).form('validate');  
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                    $('#tt').datagrid('reload');
                                }
                                else if ((result.indexOf("F") == 0)) {
                                    $.messager.alert("提示", "添加失败，请重新操作！", "info");
                                    return;
                                }
                                else if ((result.indexOf("L") == 0)) {
                                    $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                    top.location = '/index.aspx';
                                    return;
                                }

                            }

                        });
                    }
                })
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="easyui-layout" style="width: 100%; height: 100%;" id="mycon">
        <div region="west" split="true" title="区域检索" style="width: 180px; overflow: scroll" id="west">
            <ul id="pt"></ul>
        </div>
        <div region="center" style="background: #eee; overflow-y: hidden">
            <table id="tt">
            </table>
        </div>
        <div id="tab_toolbar" style="padding: 4px;">
            <table cellpadding="0" cellspacing="0" style="width: 100%">
                <tr>

                    <td style="padding-left: 2px">


                        <a href="#" onclick="newUser();" id="a_add"
                            class="easyui-linkbutton" iconcls="icon-add">添加</a>
                        <a href="javascript:void(0)" onclick="editUser() " class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
                        <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>

                    </td>
                    <td style="text-align: right; padding-right: 15px">
                        <input id="ipt_search" menu="#search_menu" />
                        <div id="search_menu" style="width: 120px">
                           
                            <div name="username">
                                类别
                            </div>
                            <div name="petname">
                                有害生物
                            </div>
                             <div name="usernum">
                                地区
                            </div>
                        </div>
                    </td>
                </tr>
            </table>

        </div>
        <div id="dlg" class="easyui-dialog" style="width: 700px; height: auto; padding: 5px"
            data-options="closed:true,buttons:'#dlg-buttons',shadow:false">

            <form id="fm" method="post">
                <div style="float: left; width:310px;">
                    <div id="dharm" class="easyui-panel" title="有害生物"
                    style="width: 300px;height:300px;  padding:2px;overflow:auto; background: #fafafa;"
                    data-options="iconCls:'icon-help',closable:false">
                        <ul id="pets"></ul>
                        <input id="ForestPets" name="ForestPets" type="hidden" />
                        </div>
                        
                </div>
                <div style="float: left; width: 300px; padding-top:50px;">
                    <div class="fitem">
                        <label>地区名：</label>
                        <input id="aname" name="aname" class="easyui-validatebox" data-options="required:true" />
                    </div>
                    <div class="fitem">
                        <label>类型名：</label>
                        <input id="sname" name="sname" class="easyui-validatebox" />
                        <input name="Test" id="test" type="hidden" />
                        <input name="Id" id="Id" type="hidden" />
                        <input name="asid" id="asid" type="hidden" />
                        <input id="key" name="key" onkeydown="if(event.keyCode==13)reloadgrid()" type="hidden" />
                    </div>

                    <div class="fitem">
                        <label>阶段：</label>
                        <input id="Stage" name="Stage" class="easyui-validatebox" />                        
                    </div>
                    <div class="fitem">
                        <label>统计单位：</label>
                        <input id="statisticunits" name="statisticunits" class="easyui-validatebox" />
                    </div>
                    <div class="fitem">
                        <label>最低值：</label>
                        <input id="harmdegreelow" name="harmdegreelow" class="easyui-validatebox" data-options="required:true" />
                    </div>
                    <div class="fitem">
                        <label>中间值：</label>
                        <input id="harmdegreecenter" name="harmdegreecenter" class="easyui-validatebox" data-options="required:true" />
                    </div>
                    <div class="fitem">
                        <label>最高值：</label>
                        <input id="harmdegreeup" name="harmdegreeup" class="easyui-validatebox" data-options="required:true" />
                    </div>
                </div>
                <div style="clear: both;"></div>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
        </div>
    </div>
</asp:Content>
